package goulu.bloggy.com.Helpers;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import android.util.Log;

import goulu.bloggy.com.R;

public class PostHelper 
{
	public static final String MOOD_EMBARRASSED = "embarrassed";
	public static final String MOOD_HAPPY = "happy";
	public static final String MOOD_JOY = "joy";
	public static final String MOOD_LAUGH = "laugh";
	public static final String MOOD_PLAIN = "plain";
	public static final String MOOD_SAD = "sad";
	public static final SimpleDateFormat MYSQL_DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	//startactivityforresult apuja
	public static final int NOTHING_CHANGED = 0;
	public static final int CONTENT_CHANGED = 1;
	
	public static int getMoodResourceId(String mood)
	{
		int moodResource = R.drawable.mood_plain;
		
		if(mood.equals(MOOD_HAPPY))
		{
			moodResource = R.drawable.mood_happy;
		}
		else if(mood.equals(MOOD_EMBARRASSED))
		{
			moodResource = R.drawable.mood_embarrassed;
		}
		else if(mood.equals(MOOD_JOY))
		{
			moodResource = R.drawable.mood_joy;
		}
		else if(mood.equals(MOOD_LAUGH))
		{
			moodResource = R.drawable.mood_laugh;
		}
		else if(mood.equals(MOOD_PLAIN))
		{
			moodResource = R.drawable.mood_plain;
		}
		else if(mood.equals(MOOD_SAD))
		{
			moodResource = R.drawable.mood_sad;
		}
		return moodResource;
	}
	
	public static String gregorianCalendarToString(GregorianCalendar gc)
	{
		String datetime = MYSQL_DATETIME_FORMAT.format(gc.getTime());
		return datetime;
	}
	
	public static GregorianCalendar stringToGregorianCalendar(String dateString) 
	{
		Log.d("stringtoGregorianCalendar()", "Parsing string = " + dateString);
		Date date;
		try {
			date = MYSQL_DATETIME_FORMAT.parse(dateString);
			GregorianCalendar cal = (GregorianCalendar)GregorianCalendar.getInstance();
			cal.setTime(date);
			//Log.d("stringToGregorianCalendar()", df.format(cal.getTime()));
			return cal;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static boolean intToBoolean(int num)
	{
		if(num == 0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	
	public static int booleanToInt(boolean bool)
	{
		if(bool == true)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
}
